﻿Chenxin.UI.MarkedManage = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: 'service/markedHandler.ashx',
    createGrid: function() {
        return new Chenxin.UI.ExpandGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            renderTo: 'marked_table',
            id: 'marked',
            hasCheckBox: false,
            columns: {
                Oprate: {
                    head: "操作",
                    width: 60,
                    sortable: false
                },
                MarkCode: {
                    head: "备案编号",
                    width: 90,
                    sortable: true
                },
                HouseAddress: {
                    head: "地址",
                    sortable: true
                },
                MarkDay: {
                    head: "备案日期",
                    width: 80,
                    sortable: true
                },
                MarkStartTime: {
                    head: "备案开始日期",
                    width: 70,
                    sortable: true
                },
                MarkEndTime: {
                    head: "备案结束日期",
                    width: 70,
                    sortable: true
                },
                PropertyCode: {
                    head: "产权证号",
                    width: 90,
                    sortable: true
                },
                PropertyPersonName: {
                    head: "产权人名",
                    width: 90,
                    sortable: true
                },
                MarkPerson: {
                    head: "业务员",
                    width: 80,
                    sortField: "MarkPersonID",
                    sortable: true
                },
                MarkDepart: {
                    head: "门店",
                    width: 80,
                    sortField: "MarkDepartId",
                    sortable: true
                },
                AddTime: {
                    head: "添加时间",
                    width: 125,
                    sortable: true
                }
            }
        })
    },
    loadInfo: function() {
        var _this = this;
        Chenxin.ajax({
            type: "post",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getmodel', modelid: _this.Id },
            onSuccess: function(data, msg) {
                if (data.model) {
                    _this.MarkedInfo = data.model;
                }
                if (data.house) {
                    _this.HouseInfo = data.house;
                }
            }
        });
    },
    cancle: function() {
    },
    initEvent: function() {
        var _this = this;
        $('.a_chang').live('click', function() {
            _this.Id = this.name;
            _this.loadInfo();
            _this.showMarked();
        });
        $('.a_delete').live('click', function() {
            _this.Id = this.name;
            _this.delMarked();
        });
    },
	delMarked:function(){
		if(!confirm('确定删除这条备案记录？')){
			return;
		}
		var _this=this;
		Chenxin.ajax({
			url:this.actionUrl,
			type:'get',
			data:{op:'del',modelid:_this.Id},
			onSuccess:function(data,msg){
				alert(msg);
				_this.grid.reload();
			}
		});
	},
    showMarked: function() {
        var _this = this;
        if (!this.markedWin) {
            this.markedWin = new Chenxin.UI.ChangeMarkedForm({
                scope: _this,
                currentId: _this.Id,
                afterShow: function() {
                    if (!this.permit.edit_permit.editall) {
                        this.findByName('MarkCode').attr('disabled', 'disabled');
                        this.findByName('PropertyCode').attr('readonly', 'readonly');
                        this.findByName('PropertyPersonName').attr('readonly', 'readonly');
                    }
                },
                afterGetFormJson: function(json) {
                    json.RecordId = _this.Id;
                    delete json.Address;
                    delete json.AddPerson;
                    delete json.AddDepart;
                    this.markedWin.additionalParam.personCode = json.changPersonCode;
                    this.markedWin.additionalParam.HouseCode = json.HouseCode;
                    delete json.changPersonCode;
                    delete json.HouseCode;
                }
            });
        }
        this.markedWin.currentId = _this.Id;
        this.markedWin.show("edit");
        var _data = {};
        _data.HouseCode = _this.HouseInfo.HouseCode;
        _data.Address = this.HouseInfo.Community + this.HouseInfo.BuildingName + this.HouseInfo.Room
        _data.AddPerson = _this.HouseInfo.AddPerson;
        _data.AddDepart = _this.HouseInfo.AddDepart;
        _data.MarkCode = _this.MarkedInfo.MarkCode;
        _data.PropertyCode = _this.MarkedInfo.PropertyCode;
        _data.PropertyPersonName = _this.MarkedInfo.PropertyPersonName;
        this.markedWin.fitData(_data);
        this.markedWin.setTitle('备案变更');
    },
    createSearch: function() {
        return new Chenxin.UI.KeyMarkedSearch({
            scope: this
        });
    },
    initComponent: function() {
        Chenxin.UI.MarkedManage.superclass.initComponent.call(this);
    }
});


/**
*查询面板
*/
Chenxin.UI.KeyMarkedSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'marked_search',
    initEvent: function() {
        var _this = this;
        $('#btn_search').click(function() {
            _this.scope.reloadGrid();
        });
    },
    createComboList: function() {
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.KeyMarkedSearch.superclass.initComponent.call(this);
    }
});

$(document).ready(function() {
    var markedMgr = new Chenxin.UI.MarkedManage();
});